-----------------------------------------------------------------------------------------
-- filename : json.lua
-- description : script to enable load JSON File
-----------------------------------------------------------------------------------------

local json = {}

function json.load( filename )
    -- set default base dir if none specified
    local base = system.ResourceDirectory
    -- create a file path for corona i/o
    local path = system.pathForFile( filename, base )
    -- will hold contents of file
    local contents
    -- io.open opens a file at path. returns nil if no file found

    local file = io.open( path, "r" )
    if file then
        -- read all contents of file into a string
        contents = file:read( "*a" )
        io.close( file )    -- close the file after using it
        --return decoded json string
        return json.decode( contents )
    else
        --or return nil if file didn't ex
        return nil
    end
end

return json